﻿using OA.Core;
using OA.Core.Attribute;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace OA.Model.MyAttribute
{
    public class TagAttribute : Attribute
    {
        public TagEnum TagName { get; set; }

        public string Verify { get; set; }

        public string Tips { get; set; }

        public int MinLength { get; set; }

        public int MaxLength { get; set; }

        public string Values { get; set; }

        public Type MyType { get; set; }

        public List<MySelectListItem> DBScore{ get; set; }

        /// <summary>
        /// 下拉 多选 单选
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="myType"></param>
        /// <param name="tips"></param>
        public TagAttribute(TagEnum tagName, Type myType, string tips,bool required)
        {
            this.TagName = tagName;
            if (required)
            {
                this.Verify = "required";
            }            
            this.Tips = tips;
            if (myType != null)
            {
                this.DBScore = MyEnum.EnumToSelectList(myType);
            }
            this.MyType = myType;
        }

        public TagAttribute(TagEnum tagName, string verify, string tips,string values)
        {
            this.TagName = tagName;
            this.Verify = verify;
            this.Tips = tips;
            this.Values = values;
            if (!string.IsNullOrWhiteSpace(values))
            {
                if (values == "0")
                {
                    this.DBScore = new List<MySelectListItem>() { new MySelectListItem() { Text = "请选择", Value = "0" } };
                }
                else
                {
                    this.DBScore = values.Split(new string[] { ",", "，" }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(m => new MySelectListItem() { Text = m, Value = m }).ToList();
                }
                
            }            
        }

        
        

        public TagAttribute(TagEnum tagName, string verify, string tips,int minLength, int maxLength)
        {
            this.TagName = tagName;
            this.Verify = verify;
            this.Tips = tips;
            this.MaxLength = maxLength;
            this.MinLength = minLength;
        }

    }

    public enum TagEnum
    {
        [Description("文本")]
        Text = 1,
        [Description("数字")]
        Number = 2,

        /// Value 保存ID  Text  保存名称
        [Description("下拉")]
        Select = 3,

        [Description("单选")]
        Radio = 4,

        /// <summary>
        /// Files 保存选择的值
        /// </summary>
        [Description("多选")]
        CheckBox = 5,
        [Description("Email")]
        Email = 6,
        [Description("开关")]
        Switch = 7,
        [Description("年")]
        Year = 8,
        [Description("年月")]
        YearMonth = 9,
        [Description("日期")]
        Date = 10,
        [Description("时间")]
        Time = 11,
        
        [Description("日期时间")]
        DateTime = 12,

        [Description("文本域")]
        TextArea = 13,

        [Description("富文本")]
        RichTextEditor = 14,

        /// <summary>
        /// Value  和 Files 都保存了数据 value string 
        /// </summary>
        [Description("单图上传")]
        SingleImageUpload = 15,

        /// <summary>
        /// Value  和 Files 都保存了数据 value string 
        /// </summary>
        [Description("单文件上传")]
        SingleFlieUpload = 16,


        [Description("多图上传")]
        MultipleImageUpload = 17,

        /// <summary>
        /// Value  和 Files 都保存了数据 value [] 
        /// </summary>
        [Description("多文件上传")]
        MultipleFlieUpload = 18,

        [Description("密码")]
        PassWord = 19,

        [Description("隐藏域")]
        Hidden = 20,

        [Description("金额")]
        Money = 21,

        /// <summary>
        /// 有问题
        /// </summary>
        [Description("员工")]
        Employee = 22,

        /// <summary>
        /// Value 保存ID  Text  保存名称
        /// </summary>
        [Description("部门")]
        Department = 23,

        /// <summary>
        /// Value 保存ID  Text  保存名称
        /// </summary>
        [Description("岗位")]
        Position = 24,

        [Description("下拉2")]
        Select2 = 25,

        [Description("只读")]
        ReadOnly = 26,


        /// <summary>
        /// Refs 保存数据  Json
        /// </summary>
        [Description("单据引用")]
        Reference = 30,
        
        /// <summary>
        /// Refs 保存Json  数据
        /// </summary>
        [Description("多个单据引用")]
        MultipleReference = 31,


        [Description("产品选择")]
        Product = 40,

        /// <summary>
        /// 往来单位  Value 保存ID  Text  保存名称
        /// </summary>
        [Description("往来单位")]
        RelatedCompany = 41,

        [Description("供应商")]
        Supplier = 42,

        [Description("客户")]
        Customer = 43,

        [Description("联系人")]
        Contact = 44,


        [Description("计算")]
        Calculate = 68,

        [Description("小计")]
        Subtotal = 69,

        [Description("总计")]
        Total = 70,


        [Description("手机号码")]
        Phone = 81,

        [Description("身份证")]
        Identity = 82,

        [Description("网址")]
        Url = 83,


        [Description("表格")]
        Table = 99,

        [Description("员工")]
        Employee2 = 122,


        [Description("部门")]
        Department2 = 123,

        /// <summary>
        /// 
        /// </summary>
        [Description("岗位")]
        Position2 = 124,

 
        /// <summary>
        /// Files 保存选择的值
        /// </summary>
        [Description("多选")]
        CheckBox2 = 135,


    }
}
